package test1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Test1 {
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver" );
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    private static  String url = "jdbc:mysql://localhost:3306/test";
    private static String user = "root";
    private static String password = "bawan114";

    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;

        try{
            connection = DriverManager.getConnection(url, user, password);
            statement= connection.createStatement();
            String sql="update t_student set name='lisi',age=22 where id='A0001'";
            int count = statement.executeUpdate(sql);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        finally {
            if(statement!=null){
                try {
                    statement.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }

            if(connection!=null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }

        }
    }
}
